﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
@* 生产任务列表页面 *@
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.20/dist/css/layui.css" rel="stylesheet" />
    @* 导出引入文件 *@
    <title>Layui with XLSX</title>
    <!-- 引入Layui的CSS -->
    @* <link rel="stylesheet" href="path/to/layui.css"> *@
    <!-- 引入XLSX库的CDN -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>
    <title>Layui 导入按钮示例</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/layui/2.6.8/css/layui.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/layui/2.6.8/layui.js"></script>
</head>
<body class="layui-padding-3">
    <h3>生产任务列表</h3>
    <br />
    <form class="layui-form layui-row layui-col-space16">
        @*  <div class="layui-col-md4">
            <div class="layui-input-wrap">
                <div class="layui-input-prefix"></div>
                <label class="layui-form-label">工艺路线编号：</label>
                <input type="text"  name="" id="ProcessNumber" class="layui-input" lay-affix="clear" style="width: 200px" />
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-input-wrap">
                <label class="layui-form-label">工艺名称：</label>
                <input type="text" lay-affix="clear" name=""  id="ProcessName"  class="layui-input" style="width: 200px" />
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-input-wrap">
                <div class="layui-input-prefix"></div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block" style="width: 200px">
                        <select name="interest" lay-filter="aihao" id="ProcessAudit">
                            <option value="0">选择状态</option>
                            <option value=true>有效</option>
                            <option value=false>无效</option>
                        </select>
                    </div>
                </div>
            </div>
        </div> *@

        <div class="layui-btn-container layui-col-xs12">
            <a class="layui-btn layui-bg-blue" style="float:right">
                <i class="layui-icon layui-icon-table"></i>
                导出表格
            </a>
            <a class="layui-btn " onclick="location.href='/ProductionTasks/ProductionTasksCreate'" style="float:right">
                <i class="layui-icon layui-icon-add-1"></i>
                新增生产任务
            </a>
            <button class="layui-btn layui-btn-primary" lay-submit lay-filter="search" style="float:right">
                <i class="layui-icon layui-icon-search"></i>
                查询
            </button>
        </div>
    </form>
    <table class="layui-hide" id="ID-table-demo-search"></table>

    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.20/dist/layui.js"></script>
    <script>
          layui.use('table',function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var util = layui.util;
            var table = layui.table;
            Seach();
              // 表单取值
            layui.$('#component').on('click', function () {
                Seach()
                return false;//阻止默认 from跳转
            });

            // 搜索提交
            function Seach() {
                var obj={

                }
                console.log(obj)
                $.ajax({
                    type: 'get',
                    url: '@ViewBag.RedDragonWrite'+"/api/ProductionTasks/SearchProductionTasks",
                    data: JSON.stringify(obj),
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        table.render({
                            elem: '#ID-table-demo-search',
                            cols: [[
                                {field:'productiontasksId', width:150, title: '序号', sort: true},
                                {field:'productiontasksCode', width:150, title: '任务编码'},
                                {field:'productiontasksName', width:150, title: '任务名称'},
                                {field:'materialName', width:150, title: '生产物料'},
                                {field:'productionQuantity', width:150, title: '生产数量'},
                                {field:'startTime', width:150, title: '开工日期',templet: '<div>{{ layui.util.toDateString(d.startTime, "yyyy-MM-dd HH:mm:ss") }}</div>'},
                                {field:'endTime', width:150, title: '完工日期',templet: '<div>{{ layui.util.toDateString(d.endTime, "yyyy-MM-dd HH:mm:ss") }}</div>'},
                                {field:'isStatus', width:150, title: '任务状态', templet: function(d){
                                    if(d.isStatus ==1){
                                        return '<span>未发放</span>';
                                    }
                                    else {
                                        return '<span>已发放</span>';
                                    }
                                }},
                                {field:'createdOwner', title: '制单人', minWidth: 150},
                                {field:'createdTime', width:150, title: '创建时间',templet: '<div>{{ layui.util.toDateString(d.createdTime, "yyyy-MM-dd HH:mm:ss") }}</div>'},
                                {field:'isStatus', width:150, title: '数据状态', templet: function(d){
                                     if(d.isStatus ==1){
                                        return '<span class="layui-badge layui-bg-gray">新建</span>';
                                    }
                                    else if(d.isStatus ==2){
                                        return '<span class="layui-badge layui-bg-red">变更</span>';
                                    }
                                    else {
                                        return '<span class="layui-badge layui-bg-blue">确认</span>';
                                    }
                                }},
                                {field:'auditStatus', width:150, title: '审批状态', templet: function(d){
                                     if(d.auditStatus ==1){
                                        return '<span class="layui-badge layui-bg-gray">未提交</span>';
                                    }
                                    else if(d.auditStatus ==2){
                                        return '<span class="layui-badge layui-bg-blue">已提交</span>';
                                    }
                                    else {
                                        return '<span class="layui-badge layui-bg-green">已审核</span>';
                                    }
                                }},//操作列
                                {fixed: 'right', width: 300, title: '操作', align:'center', templet: function (d){
                                    return '<a class="layui-btn layui-btn-xs layui-icon layui-icon-edit" lay-on="test-page-custom" onclick="Update(' + d.productiontasksId + ')">编辑</a><a class="layui-btn layui-btn-xs layui-icon layui-icon-delete" lay-event="moredel" onclick="Delete(' + d.productiontasksId + ')">删除</a > '
                                },
                            }
                            ]],
                            data: res.data,
                            page: true,
                            limits: [2, 3, 4],
                            height: 310
                        });
                        return;

                    }
                });
            };
        });
    </script>
</body>
</html>
<script>
     //导出
     function exportTableToExcel() {
         var table = document.querySelector("table.layui-table tbody");
         var ws = XLSX.utils.table_to_sheet(table);
         var wb = XLSX.utils.book_new();
         XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
         XLSX.writeFile(wb, "生产任务列表.xlsx");
     }
     document.querySelector(".layui-btn.layui-bg-blue").addEventListener("click", exportTableToExcel);
      //删除
      function Delete(productiontasksId) {
          console.log(productiontasksId)
          // 显示确认对话框
          if (confirm('您确定要删除这个数据吗？')) {
              var data = {
                  productiontasksId: productiontasksId
              };
              $.ajax({
                  url: '@ViewBag.RedDragonWrite' + "/api/ProductionTasks/DeleteProductionTasks",
                  data: JSON.stringify(data),
                  type: "delete",
                  dataType: "json",
                  contentType: "application/json",
                  success: res => {
                      if (res.code == 0) {
                          layer.msg('删除成功');
                          location.reload();
                      } else {
                          layer.msg('删除失败');
                      }
                  }
              });
          }
          else
          {
              // 用户点击了取消按钮，不执行删除操作
              layer.msg('已取消删除');
          }
      }
    //修改
    // function Update(productiontasksId) {
    //     console.log(productiontasksId)
    //     localStorage.setItem("productiontasksId", productiontasksId)
    //     location.href = '/Productiontasks/ProductiontasksUpdate';
    // }
    //修改
    function Update(productiontasksId) {
        console.log(productiontasksId)
        // localStorage.setItem("planId", planId)
        // location.href = '/Plan/PlanUpdate';
        location.href = '/Productiontasks/ProductiontasksUpdate?productiontasksId='+productiontasksId;
        // location.href = '/WorkCenter/UpdateWorkCenter?workCenterId=' + workCenterId;
    }

</script>